package com.mycity.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mycity.bean.Post;
import com.mycity.services.LocationService;
import com.mycity.services.SearchService;

@Controller
@RequestMapping("/services/search")
public class SearchController extends HelloController{
	
	SearchService searchService = new SearchService();
	
	LocationService locationService = new LocationService();

	@RequestMapping(method = RequestMethod.GET, value = "/searchPostByTag")
	public @ResponseBody List<Post> searchPostByTag(String tag) throws Exception {

		return searchService.searchByTag(tag);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/searchPostByLocation")
	public @ResponseBody List<Post> searchPostByLocation(int locationId) throws Exception {

		return searchService.searchByLocation(locationId);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/nearbyPosts")
	public @ResponseBody List<Post> nearbyPosts(int locationId) throws Exception {

		double params[] = locationService.findLatLng(locationId);
		return locationService.nearbyPosts(params[0], params[1]);
	}
}
